package com.hospital.controller;

import com.hospital.entity.Doctor;
import com.hospital.service.DoctorService;
import com.hospital.vo.DoctorVO;
import com.hospital.vo.ResponseVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author zt
 * @Date 2022/3/29
 */
@Slf4j
@RestController
@RequestMapping("/doctor")
public class DoctorController {

    @DubboReference(check = false)
    private DoctorService doctorService;

    @GetMapping("/list")
    public ResponseVO getAllDoctor() {

        List<Doctor> doctorList = doctorService.getAllDoctor(2, 3);
        return ResponseVO.buildSuccessInstance(doctorList);
    }

    @GetMapping("/getByNameAndDeptId/{name}/{deptId}")
    public ResponseVO getByNameAndDeptId(@PathVariable("name") String name, @PathVariable("deptId") Integer deptId) {
        DoctorVO byNameAndDeptId = doctorService.getByNameAndDeptId(name, deptId);
        return ResponseVO.buildSuccessInstance(byNameAndDeptId);
    }

    @PostMapping("/save")
    public ResponseVO addDoctor(DoctorVO doctorVO) {
        doctorService.addDoctor(doctorVO);
        return ResponseVO.buildSuccessInstance(ResponseVO.RESP_SUCCESS);
    }

    @PostMapping("/update")
    public ResponseVO updateDoctor(DoctorVO doctorVO) {
        doctorService.updateDoctor(doctorVO);
        return ResponseVO.buildSuccessInstance(ResponseVO.RESP_SUCCESS);
    }

    @GetMapping("/info/{id}")
    public ResponseVO doctorInfo(@PathVariable("id") Integer id) {
        DoctorVO doctorVO = doctorService.doctorInfo(id);
        return ResponseVO.buildSuccessInstance(doctorVO);
    }

    @GetMapping("/del/{id}")
    public ResponseVO delDoctor(@PathVariable("id") Integer id) {
        doctorService.delDoctor(id);
        return ResponseVO.buildSuccessInstance(ResponseVO.RESP_SUCCESS);
    }

}
